<%@page import="org.durcframework.core.UserContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>后台管理</title>
<link href="${vui}css/layout.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div id="page" class="pui-panel ui-widget ui-widget-content">
		<div class="pui-panel-titlebar ui-widget-header ui-helper-clearfix">
			<div class="ui-panel-title"><span>管理系统</span></div>
			<div class="pui-panel-right">
				<span>欢迎登录后台管理系统,<%=UserContext.getInstance().getUser().getUsername() %></span>
				<a id="modifyPswd" href="#" onclick="return false;">[修改密码]</a>
				<a class="exit" href="#" onclick="logout(); return false;">[退出]</a>
			</div>
		</div>
		<div class="pui-panel-content ui-widget-content">
			<div id="tab"></div>
		</div>
	</div>

<script type="text/javascript">
window.logout = function() {
	$.ajax({
		type: "POST",
	    url: ctx + 'logout.do',
	  	dataType:'json',
	    success: function(result){
			if (result.success){
				location.href = ctx + 'index.jsp';
			} 
		}
	});
}

VUI.use(['Layout','Dialog'],function(){
	var tab = {}; 
	var config = [];
	
	Action.post(ctx + 'listUserMenu_backuser.do',{},function(menus){
		if(menus && $.isArray(menus)) {
			for(var i=0,len=menus.length;i<len;i++) {
    			var menu = menus[i];
    			var tabId = menu.tabId;
    			var tabName = menu.tabName;
    			var configItem = getConfigItem(tabId,tabName);
    			
    			var configItemMenu = configItem.menu || [];
    			configItemMenu.push(menu);
    			configItem.menu = configItemMenu;
    		}
    		
    		// 渲染
    		for(var tabInfo in tab) {
    			var configItem = tab[tabInfo];
    			config.push(configItem);
    		}
    		
			new VUI.Layout({
				config:config
				,itemFilter:function(item) {
					if(item.url) {
						item.href = ctx + item.url + '?srId=' + item.id;
					}
				}
			});
		}
	
	});
	
	function getConfigItem(tabId,tabName) {
		var tabInfo = tabId + '|' + tabName;
		var configItem = tab[tabInfo];
		if(!configItem) {
			configItem = {
				id:tabId
				,text:tabName
			};
			tab[tabInfo] = configItem;
		}
		return configItem;
	}
	
	var dialog = new VUI.Dialog({
		url:ctx + 'sys/modifyPswd.jsp'
        ,title:'修改密码'
        ,width:420
        ,height:130
        ,buttons:[]
	});
	
	$('#modifyPswd').click(function(){
		dialog.show();
	});
	
	window.hideModifyPwsd = function() {
		dialog.close();
	}

});
</script>
</body>
</html>